package com.tuvi.nhamthin.dialog;


import com.tuvi.nhamthin.R;
import com.tuvi.nhamthin.activity.Giap;
import com.tuvi.nhamthin.helper.SqlHelper;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class ChonGoiTinh extends Dialog implements android.view.View.OnClickListener {

	 /** Button choose gender */
    Button mBtnMale;
    Button mBtnFemale;
    private String name;
    private SqlHelper dbHelper = null;
    
    /** Dialog context */
    public Context mContext;
    
	public ChonGoiTinh(Context context, String name) {
		super(context);
		// TODO Auto-generated constructor stub
		 mContext = context;
		 this.name = name;
	     requestWindowFeature(Window.FEATURE_NO_TITLE);
	     this.setContentView(R.layout.select_gender);
	     mBtnMale = (Button) findViewById(R.id.btn_male);
	     mBtnMale.setOnClickListener(this);
	     mBtnFemale = (Button) findViewById(R.id.btn_female);
	     mBtnFemale.setOnClickListener(this);
	     if (this.dbHelper == null) {
				this.dbHelper = new SqlHelper(mContext);
				
			}
	}
	
	  @Override
	  public void onClick(View v) {
	        String name = this.name.toLowerCase();
	        int gender = 0;
	        /** Button Male */
	        if (v == mBtnFemale) {
	        name = name + "_0";	
	       
	        } 
	        
	        /** Button FeMale */
	        else if (v == mBtnMale) {
	        	gender = 1;
	        	name = name + "_1";
	        }
	        dbHelper.createDatabase();
	        dbHelper.openDataBase();
	        if (dbHelper.isAdded(this.name, gender)) {
	        	 ((Giap) mContext).openDetail(name);
	             dismiss();
	        } else {
	        	 ((Giap) mContext).openActive(this.name, gender);
	             dismiss();
	        }
	        dbHelper.close();
	    }

}
